package cn.itcast.config;

import cn.itcast.interceptors.MyEasyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan("cn.itcast.controller")
@EnableWebMvc//开启springmvc对注解驱动的支持
public class SpringMvcConfig implements WebMvcConfigurer {
    //创建视图解析器
    @Bean
    public InternalResourceViewResolver creatInternalResourceViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/pages/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    //开启静态资源的支持也可是下面的形式

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
   /*//此方法用来专门注册一个Handler，来处理静态资源的，例如：图片，js，css等
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/js/**","/images/**","/css/**")
                .addResourceLocations("/js/","/images/","/css/")
                .resourceChain(true)
                .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));

    }*/

    //注册拦截器
    @Autowired
    private MyEasyInterceptor myEasyInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myEasyInterceptor);
    }
}
